home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Adobe Graphics & Publishing SDK 1996 December
/
Adobe Graphics & Publishing SDK 1996 December.iso
/
mac
/
After Effects 3.1 SDK Mac
/
Examples
/
I⁄O Samples
/
Filmstrip FXIF
/
FILM_Read.c
< prev
next >
Wrap
Text File
|
1996-06-04
|
4KB
|
212 lines
/**
FILM_Read.c
Part of the Adobe After Effects 3.1 SDK
Copyright (c)1993-96, Adobe Systems Inc, All Rights Reserved.
Revision History
1.0, created by dmw
**/
#include "Film.h"
#include "PIFormat.h"
#include "PIFormatT.h"
#include <QDOffscreen.h>
#include <stdio.h>
#include <string.h>
#include <Picker.h>
#include <AppleEvents.h>
void ReadPrepare (Ptr Stuff, long *data, short *result)
{
FormatRecordPtr fp = (FormatRecordPtr)Stuff;
fp->maxData /= 4;
*result = 0;
}
static OSErr ReadAtPos (
short fRefNum,
long pos, /* >> from begin */
long *bytes, /* <> */
void *data )
{
OSErr err = 0;
err = SetFPos(fRefNum, fsFromStart, pos);
if (!err) {
err = FSRead(fRefNum, bytes, data);
}
return err;
}
static OSErr GetFilmstripRec (
short fRefNum,
FilmStripRec *filmstrip )
{
OSErr err = 0;
long count = sizeof(FilmStripRec);
err = SetFPos(fRefNum, fsFromLEOF, -sizeof(FilmStripRec));
if (!err) {
err = FSRead(fRefNum, &count, filmstrip);
}
if (!err) {
if (filmstrip->signature != 'Rand' || count != sizeof(FilmStripRec))
err = formatCannotRead;
}
return err;
}
void ReadStart (Ptr Stuff, long *data, short *result)
{
OSErr err = 0;
FormatRecordPtr fp = (FormatRecordPtr)Stuff;
FormatRecordTPtr fpt = (FormatRecordTPtr)(Stuff - sizeof(TimeExtension));
short fRefNum = fp->dataFork;
TimeInfoHandle ti;
FilmStripRec filmstrip;
DEBUG_STR("\pBegin Read Start");
err = GetFilmstripRec(fRefNum, &filmstrip);
if (!err) {
ti = fpt->time_ext.time_info;
(**ti).fixed_fps = filmstrip.framesPerSec * 65536.0;
(**ti).duration.value = (65536 * filmstrip.numFrames) / filmstrip.framesPerSec;
(**ti).duration.scale = 65536;
(**ti).poster_time.value = 0;
(**ti).poster_time.scale = 65536;
strcpy(DH(ti)->read_name, "Filmstrip File");
DH(ti)->read_message[0] = 0;
fp->imageMode = plugInModeRGBColor;
fp->depth = 8;
fp->planes = 4;
fp->imageHRes = 72 * 65536L;
fp->imageVRes = 72 * 65536L;
fp->planeMap[0] = 0;
fp->planeMap[1] = 1;
fp->planeMap[2] = 2;
fp->planeMap[3] = 3;
fp->imageSize.h = filmstrip.width;
fp->imageSize.v = filmstrip.height;
}
DEBUG_STR("\pleaving Read Start");
*result = err;
}
void ReadContinue (Ptr Stuff, long *data, short *result)
{
OSErr err = 0;
FormatRecordPtr fp = (FormatRecordPtr)Stuff;
FormatRecordTPtr fpt = (FormatRecordTPtr)(Stuff - sizeof(TimeExtension));
TimeInfoHandle ti;
double time;
long w, h;
Handle imageH;
long frame_num;
long offset, bytes_to_read;
FilmStripRec filmRec;
DEBUG_STR("\pBegin Read Continue");
err = GetFilmstripRec(fp->dataFork, &filmRec);
if (!err) {
ti = fpt->time_ext.time_info;
time = (double)(DH(ti)->read_time.value) / (double)(DH(ti)->read_time.scale);
frame_num = time * filmRec.framesPerSec;
if (frame_num >= filmRec.numFrames)
frame_num = filmRec.numFrames - 1;
w = fp->imageSize.h;
h = fp->imageSize.v;
bytes_to_read = w * h * 4;
imageH = NewHandle(bytes_to_read);
if (imageH) {
offset = frame_num * w * (h + filmRec.leading) * 4;
HLock(imageH);
err = ReadAtPos(fp->dataFork, offset, &bytes_to_read, *imageH);
if (!err) {
fp->imageMode = plugInModeRGBColor;
fp->depth = 8;
fp->planes = 4;
fp->theRect.top = fp->theRect.left = 0;
fp->theRect.bottom = h;
fp->theRect.right = w;
fp->loPlane = 0;
fp->hiPlane = 3;
fp->colBytes = 4;
fp->rowBytes = w * 4;
fp->planeBytes = 1;
fp->data = *imageH;
if (fp->advanceState) {
(*fp->advanceState)();
} else {
*result = errPlugInHostInsufficient;
}
DisposeHandle(imageH);
fp->data = NULL;
}
} else {
err = memFullErr;
}
}
if (!err) {
*result = 0;
} else {
*result = err;
}
DEBUG_STR("\p leaving read continue");
}
void ReadFinish (Ptr Stuff, long *data, short *result)
{
FormatRecordPtr fp = (FormatRecordPtr)Stuff;
DEBUG_STR("\p begin read finish");
DEBUG_STR("\p leaving read finish");
*result = 0;
}